//
//  SaixuanViewController.m
//  CarTown
//
//  Created by 熊浩 on 15/8/3.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "SaixuanViewController.h"
#import "LXTableViewController.h"
#import "CarListTableViewController.h"
#import "CarCartoryTableViewController.h"
#import "CaChidTableViewController.h"
#import "LoadingView.h"
#import "CatMode.h"
#import "CatType.h"
#import "CarDetail.h"
#import "Position.h"
#import "NumModel.h"
#import <MJExtension.h>
#import "CatType.h"
#import "CurrtPoint.h"
@interface SaixuanViewController ()<UITableViewDataSource,UITableViewDelegate,
LXTableViewDidSelectedDelegate,CarPingPaiCheckedDelegate,CarCartoryDelegate,CaChidTableViewControllerDelegate>
{
    NSInteger count;
}
@property (weak, nonatomic) IBOutlet UITableView *tableview;
@property (weak, nonatomic) IBOutlet UIView *contener;
@property (strong,nonatomic) LXTableViewController *lxvc;
@property (strong,nonatomic) CarListTableViewController *cvc;
@property (nonatomic,strong) CarCartoryTableViewController *cavc;
@property (nonatomic,strong) CaChidTableViewController *childvc;
@property (nonatomic,strong) NSMutableArray *leftmenu;
@property (weak, nonatomic) IBOutlet UIButton *clearbtn;
@property (weak, nonatomic) IBOutlet UIButton *okbtn;
@property (nonatomic,strong) LoadingView *loadingview;
@property (nonatomic,copy) NSString *cat;
@property (nonatomic,copy) NSString *source;
@property (nonatomic,copy) NSString *cid;
@property (nonatomic,strong) CarbrandModel *brandmode;
@property (nonatomic,strong) CarprogChildmode *childmode;
@property (nonatomic,strong) CarDetail *cardetail;
@property (nonatomic,strong) NSIndexPath *carindepath;
@property (nonatomic,strong) NSIndexPath *cardetailindexpath;
@property (nonatomic,copy) NSString *num;
@property (nonatomic,assign) NSInteger type;
@property (nonatomic,copy) NSString *car_outside_color;
@property (nonatomic,copy) NSString *car_inside_color;
@property (nonatomic,copy) NSString *kuwei;
@property (nonatomic,copy) NSString *state;
@property (nonatomic,copy) NSString *xingzhi;
@property (nonatomic,strong) NSArray *catarray;
@property (nonatomic,strong) NSArray *colorarray;
@property (nonatomic,strong) NSArray *carstatearray;
@property (nonatomic,strong) NSArray *kuweiarray;
@end

@implementation SaixuanViewController

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

-(NSArray *)colorarray{
    if (_colorarray==nil) {
        _colorarray=@[@"不限",@"黑",@"白",@"棕",@"银",@"灰",@"红",@"蓝",@"金",@"绿",@"紫",@"铜",@"黄"];
    }
    return _colorarray;
}

-(NSArray *)carstatearray{
    if (_carstatearray==nil) {
        _carstatearray=@[@"不限",@"期货",@"现货"];
    }
    return _carstatearray;
}

-(NSArray *)catarray{
    if (_catarray==nil) {
        NSArray *array=[CatType getCatType];
        NSMutableArray *marray=[NSMutableArray array];
        [marray addObject:@"不限"];
        for (CatType *mode in array) {
            [marray addObject:mode.cat_name];
        }
        _catarray=marray;
    }
    return _catarray;
}

-(NSArray *)kuweiarray{
    if (_kuweiarray==nil) {
        NSArray *array=[Position getPostion];
        NSMutableArray *marray=[NSMutableArray array];
        for (Position *postion in array) {
            [marray addObject:postion.name];
        }
        _kuweiarray=marray;
    }
    return _kuweiarray;
}

-(void)carcartoryClick:(CarprogChildmode *)mode withBrandmode:(CarbrandModel *)car withIndexPath:(NSIndexPath *)indexpath{
    NSLog(@"model--%@",mode);
    self.childvc.DotNotice=NO;
    self.childmode=mode;
    self.carindepath=indexpath;
    [self showcardetail];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setExtraCellLineHidden:self.tableview];
    // Do any additional setup after loading the view.
    NSIndexPath *first=[NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableview selectRowAtIndexPath:first animated:YES scrollPosition:UITableViewScrollPositionTop];
    
    [self.cvc.view setHidden:NO];
    self.navigationItem.title=@"筛选";
    self.tableview.bounces=NO;
    [self.contener addSubview:self.loadingview];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(countchange:) name:NoticeCount object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(brandchange:) name:NoticeBrand object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cardetailchange:) name:NoticeCarDetail object:nil];
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (self.tiaojian) {
        self.brandmode=self.tiaojian[@"brand"];
        self.childmode=self.tiaojian[@"cartory"];
        self.source=self.tiaojian[SourceType];
        self.cid=self.tiaojian[CID];
        self.cardetail=self.tiaojian[@"cardetail"];
        self.kuwei=self.tiaojian[@"stock_postion"];
        self.car_outside_color=self.tiaojian[@"car_outside_color"];
        self.car_inside_color=self.tiaojian[@"car_inside_color"];
        self.xingzhi=self.tiaojian[@"sale_type"];
        self.state=self.tiaojian[@"timer"];
        self.num=self.tiaojian[@"num"];
        if (self.num) {
            [self.okbtn setTitle:[NSString stringWithFormat:@"确定（%@）",self.num] forState:UIControlStateNormal];
            if ([self.num integerValue]==0) {
                self.okbtn.enabled=NO;
            }else{
                self.okbtn.enabled=YES;
            }
            
        }self.carindepath=self.tiaojian[@"carindexpath"];
        self.cardetailindexpath=self.tiaojian[@"detailindexpath"];
        
        if (self.brandmode) {
            self.cavc.DonotNotice=YES;
            [self showcartory];
        }
        if (self.childmode) {
            self.childvc.DotNotice=YES;
            [self showcardetail];
        }
        
        if (self.car_outside_color) {
            CurrtPoint *postion=[[CurrtPoint alloc]init];
            postion.currtsection=0;
            NSInteger outpostion=[self.colorarray indexOfObject:self.car_outside_color];
            postion.currtpostion=outpostion;
            NSIndexPath *indexpath=[NSIndexPath indexPathForRow:1 inSection:0];
            UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
            cell.textLabel.text=self.car_outside_color;
            self.lxvc.currtwaiguan=postion;
        }
        if (self.car_inside_color) {
            CurrtPoint *postion=[[CurrtPoint alloc]init];
            postion.currtsection=0;
            NSInteger outpostion=[self.colorarray indexOfObject:self.car_inside_color];
            postion.currtpostion=outpostion;
            NSIndexPath *indexpath=[NSIndexPath indexPathForRow:2 inSection:0];
            UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
            cell.textLabel.text=self.car_inside_color;
            self.lxvc.currtneishi=postion;
        }
        if (self.kuwei) {
            CurrtPoint *postion=[[CurrtPoint alloc]init];
            postion.currtsection=0;
            NSInteger outpostion=[self.kuweiarray indexOfObject:self.kuwei];
            postion.currtpostion=outpostion;
            self.lxvc.currtkuwei=postion;
            NSIndexPath *indexpath=[NSIndexPath indexPathForRow:4 inSection:0];
            UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
            cell.textLabel.text=self.kuwei;
        }
        if (self.state) {
            CurrtPoint *postion=[[CurrtPoint alloc]init];
            postion.currtsection=0;
            postion.currtpostion=[self.carstatearray indexOfObject:self.state];
            self.lxvc.currtzhuangtai=postion;
            NSIndexPath *indexpath=[NSIndexPath indexPathForRow:3 inSection:0];
            UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
            cell.textLabel.text=self.state;
        }
        if (self.xingzhi) {
            CurrtPoint *postion=[[CurrtPoint alloc]init];
            postion.currtsection=0;
            postion.currtpostion=[self.catarray indexOfObject:self.xingzhi];
            self.lxvc.currtxingzhi=postion;
            NSIndexPath *indexpath=[NSIndexPath indexPathForRow:5 inSection:0];
            UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
            cell.textLabel.text=self.xingzhi;
        }
    }
    NSString *cond=[self getswicthparmas:self.tiaojian];
    [self nocticenum:cond];
    
}
-(void)CaChidcancelclick{
    self.childvc.view.hidden=YES;
    self.cavc.view.hidden=NO;
    self.childmode=nil;
    self.cardetail=nil;
    self.cavc.DonotNotice=NO;
    self.cardetailindexpath=nil;
    self.childvc.carindexpath=nil;
    self.childvc.detailindexpath=nil;
    self.source=nil;
    [self.cavc nocticenum];
}
/**
 *  显示车型
 */
-(void)showcardetail{
    self.childvc.car
    =self.brandmode;
    self.childvc.carindexpath=self.carindepath;
    self.childvc.detailindexpath=self.cardetailindexpath;
    self.childvc.mode=self.childmode;
    self.childvc.view.hidden=NO;
    self.cavc.view.hidden=YES;
}

-(void)cardetailchange:(NSNotification *)notice{
    self.cardetail=notice.userInfo[@"cardetail"];
    self.source=notice.userInfo[SourceType];
    self.cid=notice.userInfo[CID];
    self.carindepath=notice.userInfo[@"carindexpath"];
    self.cardetailindexpath=notice.userInfo[@"detailindexpath"];
}

-(void)brandchange:(NSNotification *)notice{
    self.brandmode=notice.userInfo[@"brand"];
}

-(void)countchange:(NSNotification *)notice{
    NSString *num=notice.userInfo[@"num"];
    count=[num integerValue];
    [self.okbtn setTitle:[NSString stringWithFormat:@"确定（%@）",num] forState:UIControlStateNormal];
    if ([num integerValue]==0) {
        self.okbtn.enabled=NO;
    }else{
        self.okbtn.enabled=YES;
    }
}
-(void)didselected:(NSString *)str AndIndexPath:(NSInteger)index WithLxTableChoice:(LxTableChoice)choice{
    switch (choice) {
        case KUWEI:
        {NSIndexPath *indexpath=[NSIndexPath indexPathForRow:4 inSection:0];
            UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
            if (![str isEqualToString:@"不限"]) {
                self.kuwei=str;
                
                
                cell.textLabel.text=str;
            }else{
                self.kuwei=nil;
                cell.textLabel.text=@"库位";
            }
        }
            break;
        case XINGZHI:
        {NSIndexPath *indexpath=[NSIndexPath indexPathForRow:5 inSection:0];
            UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
            if (![str isEqualToString:@"不限"]) {
                self.xingzhi=str;
                cell.textLabel.text=str;
            }else{
                self.xingzhi=nil;
                cell.textLabel.text=@"商铺性质";
            }
        }
            break;
        case NEISHI:
        {NSIndexPath *indexpath=[NSIndexPath indexPathForRow:2 inSection:0];
            UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
            if (![str isEqualToString:@"不限"]) {
                self.car_inside_color=str;
                cell.textLabel.text=str;
            }else{
                self.car_inside_color=nil;
                cell.textLabel.text=@"内饰颜色";
            }
        }
            break;
        case WAIGUAN:
        {NSIndexPath *indexpath=[NSIndexPath indexPathForRow:1 inSection:0];
            UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
            if (![str isEqualToString:@"不限"]) {
                self.car_outside_color=str;
                cell.textLabel.text=str;
            }else{
                self.car_outside_color=nil;
                cell.textLabel.text=@"外观颜色";
            }
        }
            break;
        case ZHUANGTAI:
        {NSIndexPath *indexpath=[NSIndexPath indexPathForRow:3 inSection:0];
            UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
            if (![str isEqualToString:@"不限"]) {
                cell.textLabel.text=str;
                self.state=str;
            }else{
                self.state=nil;
                cell.textLabel.text=@"车源状态";
            }
        }
            break;
        default:
            break;
    }
    
    self.childvc.DotNotice=YES;
    self.cavc.DonotNotice=YES;
    NSString *cond=[self getswicthparmas: [self perparams]];
    [self nocticenum:cond];
    
}

-(void)nocticenum:(NSString *)cond{
    NSMutableDictionary *params2=[NSMutableDictionary dictionary];
    params2[@"action"]=@"count";
    params2[@"cond"]=cond;
    [PostUitls Post:sscarurl parameters:params2 success:^(id response) {
        NSDictionary *dict=response;
        NumModel *mode=[NumModel objectWithKeyValues:dict];
        if ([mode.state integerValue]==400) {
            NSMutableDictionary *userinfo=[NSMutableDictionary dictionary];
            userinfo[@"num"]=mode.num;
            NSNotification *notice=[[NSNotification alloc]initWithName:NoticeCount object:nil userInfo:userinfo];
            [[NSNotificationCenter defaultCenter] postNotification:notice];
        }
    } failure:^(NSError *error) {
        
    }];
    
}


-(CaChidTableViewController *)childvc{
    if (_childvc==nil) {
        _childvc=[CaChidTableViewController viewcontroller];
        _childvc.view.frame=self.contener.bounds;
        _childvc.isFormSS=YES;
        _childvc.delegate=self;
        _childvc.tableView.contentInset=UIEdgeInsetsMake(64, 0, 56, 0);
        [_childvc setupHeader:XHScreenwidth-117];
        [self.contener addSubview: _childvc.view];
        [self addChildViewController:_childvc];
        
    }
    return _childvc;
}

- (IBAction)okclick:(id)sender {
    
    if (count>0) {
        [XHUserDeflaut setBool:NO forKey:ISFROMSEARCH];
        NSDictionary *tiaojian= [self perparams];
        [self postNotice:tiaojian];
        
        
        
    }
    
}

-(void)postNotice:(NSDictionary *)userinfo{
    
    if ([_delegate respondsToSelector:@selector(SaixuanOkClick:)]) {
        [_delegate SaixuanOkClick:userinfo];
    }
    
//    NSNotification *notification =[NSNotification notificationWithName:NoticeCartory object:nil userInfo:userinfo];
//    //通过通知中心发送通知
//    [[NSNotificationCenter defaultCenter] postNotification:notification];
    [self.navigationController popViewControllerAnimated:YES];
    
    
}

-(NSDictionary *)perparams{
    NSMutableDictionary *tiaojian=[NSMutableDictionary dictionary];
    
    if (self.brandmode) {
        tiaojian[@"brand"]=self.brandmode;
    }
    if (self.childmode) {
        tiaojian[@"cartory"]=self.childmode;
    }
    if (self.cardetail) {
        tiaojian[@"cardetail"]=self.cardetail;
    }
    if (self.carindepath) {
        tiaojian[@"carindexpath"]=self.carindepath;
    }
    if (self.cardetailindexpath) {
        tiaojian[@"detailindexpath"]=self.cardetailindexpath;
    }
    if (self.source) {
        tiaojian[SourceType]=self.source;
    }
    if (self.kuwei) {
        tiaojian[@"stock_postion"]=self.kuwei;
    }
    if (self.car_inside_color) {
        tiaojian[@"car_inside_color"]=self.car_inside_color;
    }
    if (self.car_outside_color) {
        tiaojian[@"car_outside_color"]=self.car_outside_color;
    }
    if (self.xingzhi) {
        
//        CatType *type=[CatType getCatTypeBytext:self.xingzhi];
        
        tiaojian[@"sale_type"]=self.xingzhi;
    }
    if (self.state) {
        tiaojian[@"timer"]=self.state;
        
        
    }
    
    return tiaojian;
}

- (IBAction)clearclick:(id)sender {
    self.brandmode=nil;
    self.cardetail=nil;
    self.childmode=nil;
    self.cardetailindexpath=nil;
    self.carindepath=nil;
    self.source=nil;
    self.cavc.view.hidden=YES;
    self.cavc.indexpath=nil;
    self.childvc.view.hidden=YES;
    self.childvc.carindexpath=nil;
    self.childvc.detailindexpath=nil;
    self.cvc.view.hidden=NO;
    self.tiaojian=nil;
    self.xingzhi=nil;
    self.state=nil;
    self.kuwei=nil;
    self.car_inside_color=nil;
    self.car_outside_color=nil;
    
    CurrtPoint *postion=[[CurrtPoint alloc]init];
    postion.currtsection=0;
    postion.currtpostion=0;
    self.lxvc.currtkuwei=postion;
    self.lxvc.currtneishi=postion;
    self.lxvc.currtxingzhi=postion;
    self.lxvc.currtzhuangtai=postion;
    self.lxvc.currtzhuangtai=postion;
    self.lxvc.currtpostion=0;
    self.lxvc.currtsection=0;
    [self.lxvc.tableView reloadData];
    [self.tableview reloadData];
    NSIndexPath *first=[NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableview selectRowAtIndexPath:first animated:YES scrollPosition:UITableViewScrollPositionTop];
    [self.cvc noticeBack];
    if ([_delegate respondsToSelector:@selector(SaixuanClearClick:)]) {
        [_delegate SaixuanClearClick:self];
    }
    
}
-(LoadingView *)loadingview{
    if (_loadingview==nil) {
        _loadingview=[LoadingView loading];
        _loadingview.frame=self.contener.bounds;
        _loadingview.hidden=YES;
    }
    return _loadingview;
}
-(LXTableViewController *)lxvc{
    if (_lxvc==nil) {
        _lxvc=[XHMianStory instantiateViewControllerWithIdentifier:@"lx"];
        _lxvc.view.frame=self.contener.bounds;
        _lxvc.tableView.contentInset=UIEdgeInsetsMake(64, 0, 56, 0);
        [self.contener addSubview:_lxvc.view];
        _lxvc.delegate=self;
        
        [_lxvc.view setHidden:YES];
    }
    return _lxvc;
}
-(void)CarCartorycancelclick{
    self.cavc.view.hidden=YES;
    self.cvc.view.hidden=NO;
    self.brandmode=nil;
    self.cavc.indexpath=nil;
    self.carindepath=nil;
    [self.cvc noticeBack];
    NSIndexPath *indexpath=[NSIndexPath indexPathForRow:0 inSection:0];
    UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
    
    cell.textLabel.text=@"车型";
}

-(CarCartoryTableViewController *)cavc{
    if (_cavc==nil) {
        _cavc=[XHMianStory instantiateViewControllerWithIdentifier:@"cavc"];
        _cavc.view.frame=self.contener.bounds;
        _cavc.tableView.contentInset=UIEdgeInsetsMake(64, 0, 56, 0);
        _cavc.delegate=self;
        [_cavc setupHeader:XHScreenwidth-117];
        [self.contener addSubview:_cavc.view];
        
        [self addChildViewController:_cavc];
        [_cavc.view setHidden:YES];
        
    }
    return _cavc;
}
-(CarListTableViewController *)cvc{
    if (_cvc==nil) {
        _cvc=[XHMianStory instantiateViewControllerWithIdentifier:@"cvc"];
        _cvc.view.frame=self.contener.bounds;
        _cvc.tableView.contentInset=UIEdgeInsetsMake(64, 0, 56, 0);
        [self.contener addSubview:_cvc.view];
        _cvc.checkeddelegate=self;
        [self addChildViewController:_cvc];
        [_cvc.view setHidden:YES];
        
    }
    return _cvc;
}
/**
 *  显示车系列表
 */
-(void)showcartory{
    if (self.carindepath) {
        self.cavc.indexpath=self.carindepath;
    }
    self.cavc.mode=self.brandmode;
    [self.leftmenu replaceObjectAtIndex:0 withObject:self.brandmode.brand_name];
    
    NSIndexPath *indexpath=[NSIndexPath indexPathForRow:0 inSection:0];
    UITableViewCell *cell= [self.tableview cellForRowAtIndexPath:indexpath];
    
    cell.textLabel.text=self.brandmode.brand_name;
    self.cavc.view.hidden=NO;
    self.cvc.view.hidden=YES;
    
}

-(void)didCarPingPaiChecked:(CarbrandModel *)mode AndIndex:(NSIndexPath *)index{
    NSLog(@"%@",mode);
    self.brandmode=mode;
    self.cavc.DonotNotice=NO;
    [self showcartory];
}
-(NSArray *)leftmenu{
    if (_leftmenu==nil) {
        
        _leftmenu=[NSMutableArray arrayWithArray:@[@"车型",@"外观颜色",@"内饰颜色",@"车源状态",@"库位",@"商户性质"]];
    }
    return _leftmenu;
}
- (void)setExtraCellLineHidden: (UITableView *)tableView{
    
    UIView *view =[ [UIView alloc]init];
    
    view.backgroundColor = [UIColor clearColor];
    
    [tableView setTableFooterView:view];
    
    [tableView setTableHeaderView:view];
    
    
}
-(NSString *)getswicthparmas:(NSDictionary *)tiaojian{
    
    
    NSString *cat_source_type=tiaojian[@"car_source_type"];
    CarbrandModel *brand=tiaojian[@"brand"];
    CarprogChildmode *child=tiaojian[@"cartory"];
    CarDetail *detail=tiaojian[@"cardetail"];
    NSString *kuwei=tiaojian[@"stock_postion"];
    NSString *caroutcolor=tiaojian[@"car_outside_color"];
    NSString *car_inside_color=tiaojian[@"car_inside_color"];
    NSString *sale_type=tiaojian[@"sale_type"];
    NSString *timer=tiaojian[@"timer"];
    NSMutableDictionary *conndict=[NSMutableDictionary dictionary];
    if (brand) {
        conndict[@"brand_name"]=brand.brand_name;
    }
    if (child) {
        conndict[@"cat_name"]=child.cat_name;
    }
    if (cat_source_type) {
        if([cat_source_type isEqualToString:@"全部平行进口车"]){
            conndict[@"expc"]=cat_source_type;
        }else if(![cat_source_type isEqualToString:@"中规"]){
            conndict[SourceType]=cat_source_type;
        }else{
            conndict[SourceType]=@"中规";
            if (detail) {
                conndict[@"mid"]=detail.ID;
            }
        }
        
    }
    if (kuwei) {
        conndict[@"stock_position"]=kuwei;
    }
    if (caroutcolor) {
        conndict[@"car_outside_color"]=caroutcolor;
    }
    if (car_inside_color) {
        conndict[@"car_inside_color"]=car_inside_color;
    }
    if (sale_type) {
        CatType *type=[CatType getCatTypeBytext:sale_type];
        
        conndict[@"sale_type"]=@([type.cat_id integerValue]);
        
    }
    if (timer) {
        if ([timer isEqualToString:@"期货"]) {
            conndict[@"timer"]=@"0";
        }else{
            conndict[@"timer"]=@"1";
            
        }
    }
    if (conndict.count>0) {
        return [NSString DataTOjsonString:conndict];
    }else{
        return @"";
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.leftmenu.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    cell.textLabel.text=self.leftmenu[indexPath.row];
    cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"button_f"]];
    cell.textLabel.highlightedTextColor=[UIColor whiteColor];
    cell.textLabel.textColor=XhColor;
    cell.textLabel.font=[UIFont systemFontOfSize:14];
    cell.backgroundColor=[UIColor clearColor];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.lxvc.view setHidden:YES];
    self.cvc.view.hidden=YES;
    self.cavc.view.hidden=YES;
    self.childvc.view.hidden=YES;
    switch (indexPath.row) {
        case 0:
        {
            if (self.brandmode) {
                self.cavc.view.hidden=NO;
            }
            
            if (self.childmode) {
                self.childvc.view.hidden=NO;
            }
            
            self.cvc.view.hidden=NO;
        }
            break;
            
            
        case 1:
        {
            
            self.lxvc.Choice=WAIGUAN;
            self.lxvc.ischeyuan=NO;
            self.lxvc.array=self.colorarray;
            [self.contener bringSubviewToFront:self.lxvc.view];
            [self.lxvc.view setHidden:NO];
        }
            break;
        case 2:
        {
            self.lxvc.Choice=NEISHI;
            self.lxvc.ischeyuan=NO;
            self.lxvc.array=self.colorarray;
            [self.contener bringSubviewToFront:self.lxvc.view];
            [self.lxvc.view setHidden:NO];
        }
            break;
        case 3:
        {
            self.lxvc.Choice=ZHUANGTAI;
            self.lxvc.ischeyuan=NO;
            self.lxvc.array=self.carstatearray;
            [self.contener bringSubviewToFront:self.lxvc.view];
            [self.lxvc.view setHidden:NO];
        }
            break;
        case 4:
        {
            self.lxvc.Choice=KUWEI;
            self.lxvc.ischeyuan=NO;
            
            self.lxvc.array=self.kuweiarray;
            [self.contener bringSubviewToFront:self.lxvc.view];
            [self.lxvc.view setHidden:NO];
        }
            break;
        case 5:
        {
            self.lxvc.Choice=XINGZHI;
            self.lxvc.ischeyuan=NO;
            self.lxvc.array=self.catarray;
            
            
            [self.contener bringSubviewToFront:self.lxvc.view];
            [self.lxvc.view setHidden:NO];
        }
            break;
        default:
            break;
    }
    
    
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
